package com.itany.corejava.day17;

public class Store {

    private int count;

    private final int MAX_SIZE;

    public Store(int size) {
        MAX_SIZE=size;
    }

    public synchronized void addData(){
        while(count==MAX_SIZE){
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        count++;
        System.out.println(Thread.currentThread().getName()+" add Data "+count);
        this.notifyAll();
    }

    public synchronized void removeData(){
        while(count==0){
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println(Thread.currentThread().getName()+" remove Data "+count);
        count--;
        this.notifyAll();
    }
}
